/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.clinicplus.service;

import br.com.foxline.clinicplus.entity.Category;
import br.com.foxline.clinicplus.entity.TemplateAppraisal;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author roniere
 */
@Stateless
public class CategoryService extends GenericService<Category> {

    public CategoryService() {
        super(Category.class);
    }

    public List<Category> getByOrdemAsc(TemplateAppraisal templateAppraisal) {
        String sql = "SELECT c FROM TemplateAppraisal t JOIN t.categorys c  WHERE";

        if (templateAppraisal != null) {
            sql += " t.id = :id ";
        }

        sql += " order by c.ordem asc ";

        Query q = getEntityManager().createQuery(sql);

        if (templateAppraisal.getName() != null) {
            q.setParameter("id", templateAppraisal.getId());
        }

        return (List<Category>) q.getResultList();
    }
}
